package algorithms.leaning.class01;

import common.util.MyUtil;

/**
 * 冒泡排序
 *
 * @author guichang
 * @date 2021/5/30
 */

@SuppressWarnings("all")
public class Code2_排序_冒泡排序 {
    public static void main(String[] args) {
        int[] nums = MyUtil.createRandomArray(10, -4, 6);
        bubbleSort(nums);
        MyUtil.printInt(nums);
    }

    /**
     * 两两之间，大数后移
     */
    public static void bubbleSort(int[] nums) {
        for (int i = nums.length - 1; i >= 0; i--) {
            for (int j = 1; j <= i; j++) {
                if (nums[j - 1] > nums[j]) {
                    MyUtil.swap(nums, j - 1, j);
                }
            }
        }
    }
}